﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;
using Component.Worker.RecursiveProcess;
using System.Collections.Generic;

public partial class AdminX_Tour_TourMan : System.Web.UI.UserControl
{
    #region Constants
    private DataTable mCateData = new DataTable();
    protected const string HOLIZOTAL_COLUMN_NAME = "HolizotalSort";
    protected const string VERTICAL_COLUMN_NAME = "VerticalSort";
    #endregion Constants

    protected void Page_Load(object sender, EventArgs e)
    {
        Alert1.HideMessage();
        this.initDataPaging();
        if (!IsPostBack)
        {
            this.SetLabelLanguage();
            this.ShowMess();
            this.BindDataToLanguageDropDownList();
            this.BindDataDurationToDropdownList();
            this.BindDataToDropCategory();
            this.BindDataToActiveDropDownList();
            this.BindDataStartDestinationToDropdownList();
            this.BindDataArrivedDestinationToDropdownList();
            this.BindDataSafeOffToDropdownList();
            this.BindDataToGrid(1);
        }
    }
    private void SetLabelLanguage()
    {
        int nDefaultLanguage = Support.GetDefaultLanguage();

        lblArrivedDestination.Text = MultipleLanguage.LBL_ArrivedDestination[nDefaultLanguage-1];
        lblKeyword.Text = MultipleLanguage.LBL_KEYWORD [nDefaultLanguage-1];
        lblLanguage.Text = MultipleLanguage.LBL_LANGUAGE [nDefaultLanguage-1];
        lblSaleOff.Text = MultipleLanguage.SALEOFF[nDefaultLanguage - 1];
        lblStartDestination.Text = MultipleLanguage.LBL_StartDestination [nDefaultLanguage-1];
        lblStatus.Text = MultipleLanguage.LBL_STATUS [nDefaultLanguage-1];
        //lblCategory.Text = MultipleLanguage.LBL_TourType [nDefaultLanguage-1];
        lblTourCat.Text = MultipleLanguage.LBL_TOURCAT[nDefaultLanguage - 1]; ;
        lblDuration.Text = MultipleLanguage.LBL_DURATION[nDefaultLanguage - 1];

        btnAddnew.Text = MultipleLanguage.BTN_ADDNEW [nDefaultLanguage-1];
        btnSaleOff.Text = MultipleLanguage.SALEOFF[nDefaultLanguage - 1];
        btnSearch.Text = MultipleLanguage.BTN_SEARCH[nDefaultLanguage-1];

        btnTourBooking.Text = MultipleLanguage.LBL_TOURBOOKING [nDefaultLanguage-1];
        btnTourDeparture.Text = MultipleLanguage.LBL_TOURDEPARTURE[nDefaultLanguage - 1];
        btnTourDestination.Text = MultipleLanguage.TOURDESTINATION[nDefaultLanguage-1];
        btnTransport.Text = MultipleLanguage.TRANSPORT[nDefaultLanguage - 1];
        btnUpdate.Text = MultipleLanguage.BTN_Update[nDefaultLanguage-1];
        btnCountry.Text = MultipleLanguage.LBL_COUNTRY[nDefaultLanguage-1];
        btnTourDuration.Text = MultipleLanguage.TOURDURATION[nDefaultLanguage-1];
        btnTourCategory.Text = MultipleLanguage.TOURCATEGORY[nDefaultLanguage-1];
        btnRegion.Text = MultipleLanguage.TOURREGION[nDefaultLanguage - 1];
    }

    #region Paging & Message
    private void initDataPaging()
    {
        Pager1.PageSize = Config.PAGESIZE;
        Pager1.ShowFirstLast = true;
        Pager1.FirstClause = "Đầu";
        Pager1.LastClause = "Cuối";
        Pager1.NextClause = "Tiếp";
        Pager1.OfClause = "của";
        Pager1.PageClause = "Trang";
        Pager1.CompactedPageCount = 5;
        Pager1.PreviousClause = "Sau";
        Pager1.MaxSmartShortCutCount = 5;
        Pager1.NotCompactedPageCount = 5;
    }
    private void VisiblePaging(int intPagecount)
    {
        int nPageSize = 0;
        nPageSize = Config.PAGESIZE;
        if (intPagecount > nPageSize)
            Pager1.Visible = true;
        else
            Pager1.Visible = false;
    }
    public void pager_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndx = Convert.ToInt32(e.CommandArgument);
        Pager1.CurrentIndex = currnetPageIndx;
        BindDataToGrid(currnetPageIndx);
    }
    private void ShowMess()
    {
        int nDefaultLanguage = Support.GetDefaultLanguage() - 1;
        int nMessage = ConvertData.ConvertToInt(Request.QueryString[Config.MESS_ID]);
        lblWarning.Text = MessagesAlert.SEARCH_NO_ITEM[nDefaultLanguage];
        switch (nMessage)
        {
            case 1:
                Alert1.ShowMessage(1, MessagesAlert.INSERT_SUCCESSFULL[nDefaultLanguage]);
                break;
            case 2:
                Alert1.ShowMessage(1, MessagesAlert.UPDATE_SUCCESSFUL[nDefaultLanguage]);
                break;
            default:
                Alert1.HideMessage();
                break;
        }
    }
    #endregion

    #region BindDataToDropDown
    private void BindDataToActiveDropDownList()
    {
        int nCurrentLang = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        ddlStatus.DataSource = Support.dtbStatus(nCurrentLang);
        ddlStatus.DataTextField = "Description";
        ddlStatus.DataValueField = "Value";
        ddlStatus.DataBind();
    }
    private void BindDataToLanguageDropDownList()
    {
        Languages objLanguage = new Languages();
        DataTable dtbLanguage = new DataTable();
        dtbLanguage = objLanguage.Search();
        ddlLanguage.DataSource = dtbLanguage;
        ddlLanguage.DataValueField = "LanguageID";
        ddlLanguage.DataTextField = "Description";
        ddlLanguage.DataBind();
    }
    private void BindDataDurationToDropdownList()
    {
        TourDuration obj = new TourDuration();
        DataTable dtb = new DataTable();

        dtb = obj.GetALL();
        ddlDuration.DataSource = dtb;
        int nCurrentLang = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        switch (nCurrentLang)
        {
            case 1:
                ddlDuration.DataTextField = "DurationDescription1";
                break;
            case 2:
                ddlDuration.DataTextField = "DurationDescription2";
                break;
            case 3:
                ddlDuration.DataTextField = "DurationDescription3";
                break;
        }
        ddlDuration.DataValueField = "DurationID";
        ddlDuration.DataBind();
        Utl.SetNonSelectToControl(ddlDuration, MultipleLanguage.AllTextItem[nCurrentLang - 1], "0");
    }
    private void BindDataToDropCategory()
    {
        int nCurrentLanguage = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        int nDefaultLang = Support.GetDefaultLanguage();
        ddlTourCat.Items.Clear();
        DataTable objTable = new DataTable();
        TourCategory objTourCategory = new TourCategory();
        objTable = objTourCategory.GetALL();
        int nCount = objTable.Rows.Count;
        FlowCategory flow = new FlowCategory(objTable, VERTICAL_COLUMN_NAME, HOLIZOTAL_COLUMN_NAME);
        flow.IDColumnName = "TourCategoryID";
        flow.ParentIDColumName = "[Parents]";
        switch (nCurrentLanguage)
        {
            case 1:
                flow.SortColumnName = "TourCategoryName1";
                break;
            case 2:
                flow.SortColumnName = "TourCategoryName2";
                break;
            case 3:
                flow.SortColumnName = "TourCategoryName3";
                break;
        }

        flow.ParentSortDirection = "ASC";
        if (flow.Execute(0))
        {
            mCateData = flow.DestinationData();
        }

        if (mCateData != null)
        {
            foreach (DataRow dr in mCateData.Rows)
            {
                if (dr != null)
                {
                    string sText = string.Empty;
                    switch (nCurrentLanguage)
                    {
                        case 1:
                            sText = Convert.ToString(dr["TourCategoryName1"]);
                            break;
                        case 2:
                            sText = Convert.ToString(dr["TourCategoryName2"]);
                            break;
                        case 3:
                            sText = Convert.ToString(dr["TourCategoryName3"]);
                            break;
                    }
                    Int16 iHolz = Convert.ToInt16(dr[HOLIZOTAL_COLUMN_NAME]);
                    textCreateMarginLeft(ref sText, iHolz);
                    ListItem item = new ListItem(sText, Convert.ToString(dr["TourCategoryID"]));
                    ddlTourCat.Items.Add(item);
                }
            }
            ddlTourCat.Items.Insert(0, new ListItem(MultipleLanguage.AllTextItem[nCurrentLanguage - 1], MultipleLanguage.DDL_SELECTVALUE[nCurrentLanguage - 1]));
        }
        else
        {
            ddlTourCat.DataSource = mCateData;
            ddlTourCat.DataTextField = "TourCategoryName";
            switch (nCurrentLanguage)
            {
                case 1:
                    ddlTourCat.DataTextField = "TourCategoryName1";
                    break;
                case 2:
                    ddlTourCat.DataTextField = "TourCategoryName2";
                    break;
                case 3:
                    ddlTourCat.DataTextField = "TourCategoryName3";
                    break;
            }
            ddlTourCat.DataValueField = "TourCategoryID";
            ddlTourCat.DataBind();
            Utl.SetNonSelectToControl(ddlTourCat, MultipleLanguage.DDL_SELECTVALUE[nCurrentLanguage - 1], MultipleLanguage.DDL_SELECTVALUE[nCurrentLanguage - 1]);
        }
    }
    private void textCreateMarginLeft(ref string text, Int16 count)
    {
        if (count > 0)
        {
            string sMargin = String.Empty;
            for (int i = 0; i < count; i++)
            {
                sMargin += "--";
                sMargin += " ";
            }
            text = sMargin + text;
        }
    }
    private void BindDataStartDestinationToDropdownList()
    {
        TourDestination obj = new TourDestination();
        DataTable dtb = new DataTable();

        dtb = obj.GetALL();
        ddlStartDestination.DataSource = dtb;
        int nCurrentLang = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        switch (nCurrentLang)
        {
            case 1:
                ddlStartDestination.DataTextField = "TourDestinationTitle1";
                break;
            case 2:
                ddlStartDestination.DataTextField = "TourDestinationTitle2";
                break;
            case 3:
                ddlStartDestination.DataTextField = "TourDestinationTitle3";
                break;
        }
        ddlStartDestination.DataValueField = "TourDestinationID";
        ddlStartDestination.DataBind();
        Utl.SetNonSelectToControl(ddlStartDestination, MultipleLanguage.AllTextItem[nCurrentLang - 1], "0");
    }
    private void BindDataArrivedDestinationToDropdownList()
    {
        TourDestination obj = new TourDestination();
        DataTable dtb = new DataTable();

        dtb = obj.GetALL();
        ddlArrivedDestination.DataSource = dtb;
        int nCurrentLang = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        switch (nCurrentLang)
        {
            case 1:
                ddlArrivedDestination.DataTextField = "TourDestinationTitle1";
                break;
            case 2:
                ddlArrivedDestination.DataTextField = "TourDestinationTitle2";
                break;
            case 3:
                ddlArrivedDestination.DataTextField = "TourDestinationTitle3";
                
                break;
        }
        ddlArrivedDestination.DataValueField = "TourDestinationID";
        ddlArrivedDestination.DataBind();
        Utl.SetNonSelectToControl(ddlArrivedDestination, MultipleLanguage.AllTextItem[nCurrentLang - 1], "0");
    }
    //private void BindDataSafeOffToDropdownList()
    //{
    //    SaleOff obj = new SaleOff();
    //    DataTable dtb = new DataTable();

    //    dtb = obj.GetALL();
    //    ddlSaleOff.DataSource = dtb;
    //    int nCurrentLang = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
    //    switch (nCurrentLang)
    //    {
    //        case 1:
    //            ddlSaleOff.DataTextField = "Title1";
    //            break;
    //        case 2:
    //            ddlSaleOff.DataTextField = "Title2";
    //            break;
    //        case 3:
    //            ddlSaleOff.DataTextField = "Title3";
    //            break;
    //    }
    //    ddlSaleOff.DataValueField = "SaleOffID";
    //    ddlSaleOff.DataBind();
    //    switch (nCurrentLang)
    //    {
    //        case 1:
    //            Utl.SetNonSelectToControl(ddlSaleOff, "-- Tất cả --", "------ Rỗng ------");
    //            break;
    //        case 2:
    //            Utl.SetNonSelectToControl(ddlSaleOff, "------ All ------", "------ Null ------");
    //            break;
    //        case 3:
    //            Utl.SetNonSelectToControl(ddlSaleOff, "------ All ------", "------ Null ------");
    //            break;
    //    }
    //}
    private void BindDataSafeOffToDropdownList()
    {
        ddlSaleOff.Items.Clear();
        int nCurrentLang = ConvertData.ConvertToInt(ddlLanguage.SelectedValue) - 1;
        ListItem item0 = new ListItem(MultipleLanguage.AllTextItem [nCurrentLang], "0");
        ddlSaleOff.Items.Add(item0);
        ListItem item1 = new ListItem(MultipleLanguage.SALEOFF1[nCurrentLang], "1");
        ddlSaleOff.Items.Add(item1);
        ListItem item2 = new ListItem(MultipleLanguage.SALEOFF2[nCurrentLang], "2");
        ddlSaleOff.Items.Add(item2);
        ListItem item3 = new ListItem(MultipleLanguage.SALEOFF3[nCurrentLang], "3");
        ddlSaleOff.Items.Add(item3);
    }
    protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.SetLabelLanguage();
        this.BindDataToActiveDropDownList();
        this.BindDataStartDestinationToDropdownList();
        this.BindDataArrivedDestinationToDropdownList();
        this.BindDataDurationToDropdownList();
        this.BindDataSafeOffToDropdownList();
        this.BindDataToDropCategory();
        this.BindDataToGrid(1);
    }
    protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.SetLabelLanguage();
        this.BindDataToActiveDropDownList();
        this.BindDataStartDestinationToDropdownList();
        this.BindDataArrivedDestinationToDropdownList();
        this.BindDataDurationToDropdownList();
        this.BindDataSafeOffToDropdownList();
        this.BindDataToDropCategory();
        this.BindDataToGrid(1);

    }
    #endregion

    #region Click Events
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindDataToGrid(1);
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        int nDefaultLanguage = Support.GetDefaultLanguage();
        // Update  data
        int nCount = dtgTour.Items.Count;

        for (int i = 0; i < nCount; i++)
        {
            TextBox txtPriority = (TextBox)dtgTour.Items[i].FindControl("txtPriority");
            Label lblID = (Label)dtgTour.Items[i].FindControl("lblTourID");

            int nNewsID = ConvertData.ConvertToInt(lblID.Text);
            int nPriority = ConvertData.ConvertToInt(txtPriority.Text);

            Tours objNews = new Tours();
            int nResult = objNews.UpdatePriority(nNewsID, nPriority);

            if (nResult > 0) { Alert1.ShowMessage(1, MessagesAlert.UPDATE_SUCCESSFUL[nDefaultLanguage - 1]); }
            else { Alert1.ShowMessage(2, MessagesAlert.UPDATE_UNSUCCESSFUL[nDefaultLanguage - 1]); }
        }
        this.BindDataToGrid(1);
    }
    protected void btnAddnew_Click1(object sender, EventArgs e)
    {
        string sAdd = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOUR_ADD;
        Response.Redirect(sAdd);
    }
    protected void btnTourDestination_Click(object sender, EventArgs e)
    {
        string sTourDestination = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURDESTINATION;
        Response.Redirect(sTourDestination);
    }
    protected void btnArrivedDestination_Click(object sender, EventArgs e)
    {
        string sTourDestination = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_ARRIVEDDESTINATION;
        Response.Redirect(sTourDestination);
    }
    protected void btnTourBooking_Click(object sender, EventArgs e)
    {
        string sTransport = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURBOOKING;
        Response.Redirect(sTransport);
    }
    protected void btnTransport_Click(object sender, EventArgs e)
    {
        string sTransport = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TRANSPORT;
        Response.Redirect(sTransport);
    }
    protected void btnTourDeparture_Click(object sender, EventArgs e)
    {
        string sTourDeparture = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURDEPARTURE;
        Response.Redirect(sTourDeparture);
    }
    protected void btnSaleOff_Click(object sender, EventArgs e)
    {
        string sSaleOff = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURSALEOFF;
        Response.Redirect(sSaleOff);
    }
    protected void btnTourCategory_Click(object sender, EventArgs e)
    {
        string sCountry = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURCATEGORY;
        Response.Redirect(sCountry);
    }
    protected void btnTourDuration_Click(object sender, EventArgs e)
    {
        string sCountry = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOURDURATION;
        Response.Redirect(sCountry);
    }
    protected void btnCountry_Click(object sender, EventArgs e)
    {
        string sCountry = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_COUNTRY;
        Response.Redirect(sCountry);
    }
    protected void btnRegion_Click(object sender, EventArgs e)
    {
        string sregion = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_REGION;
        Response.Redirect(sregion);
    }
    #endregion

    #region BindDataToGrid
    private void BindDataToGrid(int CurrentPageIndex)
    {
        int nItemView = 0;
        int nItemID = 0;
        int nStatus = ConvertData.ConvertToInt(ddlStatus.SelectedValue);
        string sSearch = ConvertData.ConvertStringToDB(txtKeyword.Text.Trim());
        int nPageSize = Config.PAGESIZE;
        int nPageCount = Config.PAGECOUNT;
        int nDefaultLanguage = Support.GetDefaultLanguage();
        int nLanguageID = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        int nStartDestination = ConvertData.ConvertToInt(ddlStartDestination.SelectedValue);
        int nArrivedDestination = ConvertData.ConvertToInt(ddlArrivedDestination.SelectedValue);
        int nSaleOff = ConvertData.ConvertToInt(ddlSaleOff.SelectedValue);
        int nTourDuration = ConvertData.ConvertToInt(ddlDuration.SelectedValue);

        int nCategory = ConvertData.ConvertToInt(ddlTourCat.SelectedValue);
        TourCategory objTourCategory = new TourCategory();
        DataTable dtbTourCategory = new DataTable();
        dtbTourCategory = objTourCategory.SearchByParent(nCategory);
        int nCount = dtbTourCategory.Rows.Count;
        string sParent = "";
        if (nCategory != -1)
        {
            sParent = ConvertData.ConvertToString(nCategory);
        }
        if (nCount > 0)
        {

            for (int i = 0; i < nCount; i++)
            {
                sParent = sParent + "," + ConvertData.ConvertToString(dtbTourCategory.Rows[i]["TourCategoryID"]) + ",";

                TourCategory objTourCategory2 = new TourCategory();
                DataTable dtbTourCategory2 = new DataTable();
                dtbTourCategory2 = objTourCategory2.SearchByParent(ConvertData.ConvertToInt(dtbTourCategory.Rows[i]["TourCategoryID"]));
                int nCount2 = dtbTourCategory2.Rows.Count;
                if (nCount2 > 0)
                {

                    for (int y = 0; y < nCount2; y++)
                    {
                        sParent = sParent + "," + ConvertData.ConvertToString(dtbTourCategory2.Rows[y]["TourCategoryID"]) + ",";

                        TourCategory objTourCategory3 = new TourCategory();
                        DataTable dtbTourCategory3 = new DataTable();
                        dtbTourCategory3 = objTourCategory3.SearchByParent(ConvertData.ConvertToInt(dtbTourCategory2.Rows[y]["TourCategoryID"]));
                        int nCount3 = dtbTourCategory3.Rows.Count;
                        if (nCount3 > 0)
                        {
                            for (int z = 0; z < nCount3; z++)
                            {
                                sParent = sParent + "," + ConvertData.ConvertToString(dtbTourCategory3.Rows[z]["TourCategoryID"]) + ",";

                                TourCategory objTourCategory4 = new TourCategory();
                                DataTable dtbTourCategory4 = new DataTable();
                                dtbTourCategory4 = objTourCategory4.SearchByParent(ConvertData.ConvertToInt(dtbTourCategory3.Rows[z]["TourCategoryID"]));
                                int nCount4 = dtbTourCategory4.Rows.Count;
                                if (nCount4 > 0)
                                {
                                    for (int z1 = 0; z1 < nCount4; z1++)
                                    {
                                        sParent = sParent + "," + ConvertData.ConvertToString(dtbTourCategory4.Rows[z1]["TourCategoryID"]) + ",";
                                    }
                                }
                            }
                        }
                    }
                }
            }
            sParent = sParent.Replace(",,", ",");
            sParent = ConvertData.TruncateString(sParent, sParent.Length - 1);
        }

        DataTable dtbTour = new DataTable();
        Tours objTour = new Tours();
        nPageCount = 10;
        dtbTour = objTour.Search(nItemView, nItemID, sSearch, nStartDestination, nArrivedDestination, nSaleOff,
            0, nTourDuration, sParent, nDefaultLanguage, nLanguageID, nStatus, CurrentPageIndex, nPageSize, ref nPageCount);

        lblTotalRecord.Text = MultipleLanguage.LBL_TOTAL_ITEM[nDefaultLanguage - 1] + nPageCount + MultipleLanguage.LBL_FOUND[nDefaultLanguage - 1];

        Pager1.ItemCount = dtbTour.Rows.Count;
        VisiblePaging(dtbTour.Rows.Count);

        dtgTour.DataSource = dtbTour;
        dtgTour.DataBind();
        Pager1.ItemCount = nPageCount;

        if (dtbTour.Rows.Count > 0)
            tblWarning.Visible = false;
        else
            tblWarning.Visible = true;

        txtKeyword.Focus();
        txtKeyword.Text = ConvertData.RemoveHTMLTag(txtKeyword.Text.Trim());
    }
    protected void dtgTour_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        int nDefaultLanguage = Support.GetDefaultLanguage();
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);
        Tours objTours = new Tours();
        switch (strCommand)
        {
            case "Delete":
                objTours.LoadById(nID);
                string sDelImage = Support.DeleteFile("tour", ConvertData.ConvertToString(objTours.Data.Image));

                int nDelete = objTours.DeleteById(nID);
                if (nDelete > 0)
                {
                    Alert1.ShowMessage(1, MessagesAlert.DELETE_SUCCESSFULL[nDefaultLanguage - 1]);
                    BindDataToGrid(Pager1.CurrentIndex);
                }
                else
                    Alert1.ShowMessage(2, MessagesAlert.DELETE_UNSUCCESSFULL[nDefaultLanguage - 1]);
                break;
            case "Edit":
                string sEdit = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TOUR_ADD + "&" + Config.ACTION + "=" + Config.ACTION_EDIT + "&" + Config.ACTION_ID + "=" + nID;
                Response.Redirect(sEdit);
                break;

            case "Active":
                int nActive = objTours.UpdateStatus(nID, EnumeType.INACTIVE);
                if (nActive > 0)
                    Alert1.ShowMessage(1, MessagesAlert.INACTIVE_SUCCESSFUL[nDefaultLanguage]);
                else
                    Alert1.ShowMessage(2, MessagesAlert.INACTIVE_UNSUCCESSFUL[nDefaultLanguage]);
                BindDataToGrid(Pager1.CurrentIndex);
                break;

            case "Inactive":
                int nInactive = objTours.UpdateStatus(nID, EnumeType.ACTIVE);
                if (nInactive > 0)
                    Alert1.ShowMessage(1, MessagesAlert.ACTIVE_SUCCESSFUL[nDefaultLanguage]);
                else
                    Alert1.ShowMessage(1, MessagesAlert.ACTIVE_UNSUCCESSFUL[nDefaultLanguage]);
                BindDataToGrid(Pager1.CurrentIndex);
                break;
        }
    }
    protected void dtgTour_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        int nCurrentLangID = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        int nDefaultLanguage = Support.GetDefaultLanguage();
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblTitle = (Label)e.Item.FindControl("lblTitle");
            Label lblStartDestination = (Label)e.Item.FindControl("lblStartDestination");
            Label lblArrivedDestination = (Label)e.Item.FindControl("lblArrivedDestination");
            Label lblCategory = (Label)e.Item.FindControl("lblCategory");
            LinkButton lnkEdit = (LinkButton)e.Item.FindControl("lnkEdit");
            LinkButton lnkDelete = (LinkButton)e.Item.FindControl("lnkDelete");
            LinkButton lnkActive = (LinkButton)e.Item.FindControl("lnkActive");
            LinkButton lnkInactive = (LinkButton)e.Item.FindControl("lnkInactive");
            TextBox txtPriority = (TextBox)e.Item.FindControl("txtPriority");
            Label lblTourID = (Label)e.Item.FindControl("lblTourID");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "TourID"));
            
            int nStatus = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "Status"));
            string nPriority = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Priority"));
            string sItemTitle = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title"));

            lblTourID.Text = ConvertData.ConvertToString(nID);
            if (sItemTitle == "")
                sItemTitle = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title_Default"));
            if (sItemTitle.Length > 80)
                sItemTitle = ConvertData.TruncateString(sItemTitle, 80) + Config.DOT;
            lblTitle.Text = sItemTitle;
            txtPriority.Text = nPriority;

            switch (nCurrentLangID)
            {
                case 1: // Vietnam
                    lblStartDestination.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "StartDestinationTitle1"));
                    lblArrivedDestination.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ArrivedDestinationTitle1"));
                    
                    break;
                case 2: //English
                    lblStartDestination.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "StartDestinationTitle2"));
                    lblArrivedDestination.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ArrivedDestinationTitle2"));
                    
                    break;
                case 3:
                    lblStartDestination.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "StartDestinationTitle3"));
                    lblArrivedDestination.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ArrivedDestinationTitle3"));
                    
                    break;
            }

            if (nStatus > 0)
            {
                lnkActive.Visible = true;
                lnkInactive.Visible = false;
            }
            else
            {
                lnkActive.Visible = false;
                lnkInactive.Visible = true;
            }
            lnkActive.Text = MultipleLanguage.STATUS_ACTIVE[nCurrentLangID - 1];
            lnkInactive.Text = MultipleLanguage.STATUS_INACTIVE[nCurrentLangID - 1];

            lnkEdit.Text = MultipleLanguage.BTN_EDIT[nDefaultLanguage - 1];
            lnkDelete.Text = MultipleLanguage.BTN_DELETE[nDefaultLanguage - 1];
            lnkActive.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID"));
            lnkActive.OnClientClick = Support.CreateConfirmBoxClient(MessagesAlert.INACTIVE_ALERT[nDefaultLanguage - 1]);
            lnkDelete.Enabled = true;
            lnkActive.Enabled = true;
            lnkDelete.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID"));
            lnkDelete.OnClientClick = Support.CreateConfirmBoxClient(MessagesAlert.DELETE_ALERT[nDefaultLanguage - 1]);
            lnkInactive.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID"));
            lnkInactive.OnClientClick = Support.CreateConfirmBoxClient(MessagesAlert.ACTIVE_ALERT[nDefaultLanguage - 1]);
            lnkEdit.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID"));
        }
    }
    #endregion
    
}